package com.example.viewpagertest2;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

/**
 * Created by Michael on 2015/1/13.
 */
public class Fragment1 extends Fragment implements RuleInterface,View.OnTouchListener{

    private RuleView ruleView;

    private View view;

    private Button button;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.test_view1,container,false);


        button = (Button) view.findViewById(R.id.fragment1_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(),"fragment1被点击了",Toast.LENGTH_SHORT).show();
            }
        });
        ruleView = (RuleView) view.findViewById(R.id.rule_view);
        ruleView.setRuleInterface(this);

        return view;
    }

    @Override
    public void timeButtonListener() {
        Toast.makeText(getActivity(),"Fragment1:时间",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void heatButtonListener() {
        Toast.makeText(getActivity(),"Fragment1:热度",Toast.LENGTH_SHORT).show();
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()){
            default:
                Log.e("Fragment1","触屏了");
                ruleView.hideView();
                break;
        }

        return false;
    }

}
